package com.roc.template.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName DateUtils
 * @Description: TODO
 * @Author Administrator
 * @Date 2020/7/16 13 25
 * @Version V1.0
 **/
public class DateUtils {

    public static SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddhhmmss");

    protected static Logger logger = LoggerFactory.getLogger(DateUtils.class);

    /**
     * 时间戳格式转日期格式
     * @MethodName: tranLongToDate
     * @Description: TODO
     * @Param: [time]
     * @Return: java.util.Date
     * @Author: Administrator
     * @Date: 2020/7/16
    **/
    public static Date  tranLongToDate(long time) {

        String dateString = sf.format(time);
        Date date = null;

        try {
            date = sf.parse(dateString);
        } catch (ParseException e) {
            logger.error("字符串转日期格式失败！"+ e.getMessage());
        }
        return date;
    }

    public  static  int getMonthYear() {
        int year = Calendar.getInstance().get(1);
        int month = Calendar.getInstance().get(2);
        int nwYearMonth = year * 100 + month + 1;
        return  nwYearMonth;
    }


}
